import { Component, OnInit, HostBinding, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { MatDialog, } from '@angular/material'
import { NewProjectComponent } from "../new-project/new-project.component";
import { InviteProjectComponent} from "../invite-project/invite-project.component";
import { ConfirmDialogComponent} from "../../shared/confirm-dialog/confirm-dialog.component";
import {slideToRight} from "../../anims/router.anim";

@Component({
  selector: 'app-project-list',
  templateUrl: './project-list.component.html',
  styleUrls: ['./project-list.component.scss'],
  animations:[slideToRight],
  // 页面刷新策略
  changeDetection:ChangeDetectionStrategy.OnPush,
})
export class ProjectListComponent implements OnInit {
  projects = [
    {
      'name':'企业协作',
      'desc':'这是内部项目',
      'coverImg':'assets/image/covers/0.jpg'
    },
    {
      'name':'企业协作',
      'desc':'这是内部项目',
      'coverImg':'assets/image/covers/1.jpg'
    }
  ]

  constructor(public dialog: MatDialog, private cd:ChangeDetectorRef) { }
  @HostBinding('@routerAnim')

  ngOnInit() {
  }
  // 打开新建项目
  openNewProjectDialog(){
    const dialogRef = this.dialog.open(NewProjectComponent,{data:{title:'新建项目'}});
    dialogRef.afterClosed().subscribe((result) => {
      // 手动检查视图更新
      this.cd.markForCheck()
    })

  }
  // 打开邀请组件
  launchInviteDialog(){
    const dialogRef = this.dialog.open(InviteProjectComponent);
    dialogRef.afterClosed().subscribe((result) => {} )

  }
  // 打开编辑组件
  launchUpdateDialog(){
    const dialogRef = this.dialog.open(NewProjectComponent,{data:{title:'编辑项目'}});
    dialogRef.afterClosed().subscribe((result) => {})
  }
  // 打开删除
  launchConfirmDialog(){
    const dialogRef = this.dialog.open(ConfirmDialogComponent,{data:{title:'删除项目'}});
    dialogRef.afterClosed().subscribe((result) => {
      console.log(result)
      // 手动检查视图更新
      this.cd.markForCheck()
    })
  }
}
